package com.yyx.app1.My_function.UI;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.UiThread;
import android.support.v7.app.AlertDialog;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.VolleyError;
import com.yyx.app1.Data.WebOperation;
import com.yyx.app1.Interface.Trancaction;
import com.yyx.app1.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.json.JSONObject;

/**
 * Created by Administrator on 2015/10/24.
 */
@EActivity(R.layout.activity_myappointment)
public class MyAppointment_Activity extends Activity {

    @ViewById
    TextView content;

    @ViewById
    Button am_button;

    @AfterViews
    public void itit()
    {
        IsAdministerator();
    }

    @Background
    public void IsAdministerator()
    {
        //查询是否管理员
        UIinit(true);
    }

    @UiThread
    public void UIinit(boolean is)
    {
        if (is)
        {
            finish();
            startActivity(new Intent(MyAppointment_Activity.this,HospitalAppointment_Activity_.class));
        }
    }

    @Click
    public void am_button()
    {
        new AlertDialog.Builder(this).setTitle("申请").setMessage("提交申请，由杏林医生管理员审核信息是否真实").setPositiveButton("是", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                applicationAdministrator();
            }
        }).setNegativeButton("否",null).show();
    }

    @Background
    public void applicationAdministrator()
    {
        String function =null;
        String[] parameterName = null;
        String[] parameterValue = null;
        WebOperation.JsonRequest(this, function, parameterName, parameterValue, new Trancaction() {
            @Override
            public void onResponse(JSONObject response) {
                //缺少判断返回数据
                boolean result = true;
                afterApplication(result);
            }

            @Override
            public Request.Priority getPriority() {
                return Request.Priority.HIGH;
            }

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
    }

    @UiThread
    public void afterApplication(boolean result)
    {
        if (result)
        {
            content.setText("信息审核已经提交，请耐心等待审核结果!");
        }
        else
        {
            content.setText("申请拒绝,咨询管理员后请重试!");
        }
    }

    @Click
    public void home()
    {
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            home();
        }
        return true;
    }
}
